package chapter.tenth.item66;

import java.util.concurrent.TimeUnit;

public class StopThread {
	//变量放入静态块
	private static boolean stopRequested;
	
	/**
	 * 此示例和书本上表现的结果不同，待考证
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String[] args) 
			throws InterruptedException {
		Thread backThread = new Thread(new Runnable(){

			public void run() {
				int i=0;
				System.out.println(i);
				while(!stopRequested){
					System.out.println(i);
					i++;
				}
			}
		});
		backThread.start();
		TimeUnit.SECONDS.sleep(1);
		stopRequested = true;
	}
}
